//
//  BiAlertView.m
//  FindCar
//
//  Created by bindu on 14-7-24.
//  Copyright (c) 2014年 QiHe. All rights reserved.
//

#import "BiAlertView.h"

@interface BiAlertView()
{
    UILabel * _tipsLabel;
}
@end

@implementation BiAlertView
@synthesize delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // Initialization code
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        
        UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(40, 164, 240, 127)];
        [alertView setBackgroundColor:[UIColor whiteColor]];
        [self addSubview:alertView];
      //  [alertView release];
        
        _tipsLabel = GET_LABEL(CGRectMake(0, 29, 240, 14), 14, NO, UIColorFromRGB(0x6e6e6e), NSTextAlignmentCenter);
        [_tipsLabel setBackgroundColor:[UIColor clearColor]];
        [alertView addSubview:_tipsLabel];
        
        UIButton * cancelBtn = GET_BUTTON(CGRectMake(20, 66, 90, 40), 14, NO, [UIColor whiteColor]);
        [cancelBtn setBackgroundImage:[LOAD_IMAGE_WITH_CACHE(@"tip/short_btn.png") stretchableImageWithLeftCapWidth:20 topCapHeight:30] forState:UIControlStateNormal];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(onCancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [alertView addSubview:cancelBtn];
        
        UIButton * okBtn = GET_BUTTON(CGRectMake(130, 66, 90, 40), 14, NO, [UIColor whiteColor]);
        [okBtn setBackgroundImage:[LOAD_IMAGE_WITH_CACHE(@"tip/short_btn.png") stretchableImageWithLeftCapWidth:20 topCapHeight:30] forState:UIControlStateNormal];
        [okBtn setTitle:@"确定" forState:UIControlStateNormal];
        [okBtn addTarget:self action:@selector(onOkBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [alertView addSubview:okBtn];
    }
    return self;
}

- (void)setTipText:(NSString*)tipText
{
    if ([tipText isKindOfClass:[NSString class]])
    {
        _tipsLabel.numberOfLines = 0;
        [_tipsLabel setText:tipText];
    }
}

- (void)onCancelBtnClick
{
    [self removeFromSuperview];
}

- (void)onOkBtnClick
{
    if (nil != self.delegate)
    {
        [self.delegate onAlertViewOkBtnClick];
    }
    [self removeFromSuperview];
}

@end
